/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tbgb.components.twodimesion;

/**
 *
 * @author LưuQuang
 */
public class Rectangle implements BoundComponent{
    public PositionComponent Position;
    public SizeComponent Size;
    
    public Rectangle(PositionComponent positionComponent, SizeComponent sizeComponent)
    {
        this.Position = positionComponent;
        this.Size = sizeComponent;
    }
    
    public float getLeft()
    {
        return this.Position.X().getFloat();
    }
    
    public float getRight()
    {
        return this.Position.X().getFloat() + this.Size.width().getFloat();
    }
    
    public float getTop()
    {
        return this.Position.Y().getFloat();
    }
    
    public float getBottom()
    {
        return this.Position.Y().getFloat() + this.Size.height().getFloat();
    }
    
    public void setLeft(float left)
    {
        this.Position.X().set(left);
    }
    
    public void setRight(float right)
    {
        this.Size.width().set(right - this.Position.X().getFloat());
    }
    
    public void setTop(float top)
    {
        this.Position.Y().set(top);
    }
    
    public void setBottom(float bottom)
    {
        this.Size.height().set(bottom - this.Position.Y().getFloat());
    }

    public PositionComponent getPositionComponent() {
        return this.Position;
    }

    public SizeComponent getSizeComponent() {
        return this.Size;
    }

    public float getCenterX() {
        return (this.getRight()- this.getLeft()) / 2;
    }

    public float getCenterY() {
        return (this.getBottom() - this.getTop()) / 2;
    }

    public void setCenterX(float cX) {
        this.setLeft(cX + this.Size.width().getFloat() / 2);
    }

    public void setCenterY(float cY) {
        this.setTop(cY + this.Size.height().getFloat() / 2);
    }
}